package com.aqielife.demo;

import cn.easyes.starter.register.EsMapperScan;
import com.aqielife.common.objectpool.datasource.AqieDataSource;
import com.aqielife.common.objectpool.datasource.DataSourceEndpoint;


import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRepositoriesAutoConfiguration;
import org.springframework.boot.autoconfigure.data.elasticsearch.ReactiveElasticsearchRestClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;


//@ImportResource(locations = {"classpath:applicationContext-dubbo-producer.xml"})

@Slf4j
@EsMapperScan("com.aqielife.demo.elasticsearch.esmapper")
@ComponentScan(basePackages = {"com.aqielife.demo", "com.aqielife.demo.handler"})
@SpringBootApplication(exclude = {ReactiveElasticsearchRepositoriesAutoConfiguration.class, ReactiveElasticsearchRestClientAutoConfiguration.class})
public class DemoApplication {

  @Bean
  @Primary
  public DataSource dataSource() {
    return new AqieDataSource();
  }

  @Bean
  public DataSourceEndpoint dataSourceEnpoint() {
      DataSource dataSource = this.dataSource();
      return new DataSourceEndpoint((AqieDataSource) dataSource);
  }

  public static void main(String[] args) throws Exception {
    SpringApplication.run(DemoApplication.class, args);
  }

}
